home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 131 / XENIATGM131.iso / Shareware / openOffice.org 641 / Windows / f_0266 / ConvertRun.xba < prev    next >
Extensible Markup Language  |  2001-11-19  |  10KB  |  318 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
  3. <script:module xmlns:script="http://openoffice.org/2000/script" script:name="ConvertRun" script:language="StarBasic">Option Explicit
  4.  
  5. Public oPreSelRange as Object
  6.  
  7. ' Todo Den Bug mit der Statuszeilengeschichte ├╝berpr├╝fen
  8. ' Todo Vorselektion der Listbox
  9. ' Mauspointer umschalten:
  10.  
  11. ' Todo: In der Hilfe sollte ein Hinweis erscheinen, dass immer zwei Nachkommastellen angezeigt werden
  12. ' und die resultierende Betrag ebenfalls bis auf zwei Stellen nach dem Komma gerundet wird
  13.  
  14. Sub Main()
  15.     BasicLibraries.LoadLibrary("Tools")
  16.     If InitResources("Euro Converter", "eur") Then
  17.         bDoUnProtect = False
  18.         bPreSelected = True
  19.         oDocument = ThisComponent
  20.         RetrieveDocumentObjects()                                            ' Statusline, SheetsCollection etc.
  21.         InitializeConverter(oDocument.CharLocale, 1)
  22.         GetPreSelectedRange()
  23.         If GoOn Then
  24.             DialogConvert.GetControl("chkComplete").SetFocus()    
  25.             DialogConvert.Execute
  26.         Else
  27.             DialogConvert.Dispose
  28.         End If
  29.     End If
  30. End Sub
  31.  
  32.  
  33. Sub SelectListItem()
  34. Dim Listbox as Object
  35. Dim oListSheet as Object
  36. Dim CurStyleName as String
  37. Dim oCursheet as Object
  38. Dim oTempRanges as Object
  39. Dim sCurSheetName as String
  40. Dim RangeName as String
  41. Dim oSheetRanges as Object
  42. Dim ListIndex as Integer
  43. Dim a as Integer
  44. Dim i as Integer
  45. Dim n as Integer
  46. Dim m as Integer
  47. Dim MaxIndex as Integer
  48.     Listbox = DialogModel.lstSelection
  49.     If Ubound(Listbox.SelectedItems()) > -1 Then
  50.         EnableStep1DialogControls(False, False, False)
  51.         oSelRanges = oDocument.createInstance("com.sun.star.sheet.SheetCellRanges")
  52.  
  53.         ' Is the sheet the basis, then the sheetobject has to be created
  54.         If DialogModel.optDocRanges.State = 1 Then
  55.             ' Document is the basis for the conversion
  56.             ListIndex = Listbox.SelectedItems(0)
  57.             oCurSheet = RetrieveSheetoutofRangeName(Listbox.StringItemList(ListIndex))
  58.             oDocument.CurrentController.SetActiveSheet(oCurSheet)
  59.         Else
  60.             oCurSheet = oDocument.CurrentController.ActiveSheet
  61.         End If
  62.         sCurSheetName = oCurSheet.Name
  63.         If DialogModel.optCellTemplates.State = 1 Then
  64.             Dim CurIndex as Integer
  65.             For i = 0 To Ubound(Listbox.SelectedItems())
  66.                 CurIndex = Listbox.SelectedItems(i)
  67.                 CurStylename = Listbox.StringItemList(CurIndex)
  68.                 oSheetRanges = oCursheet.CellFormatRanges.createEnumeration
  69.                 While oSheetRanges.hasMoreElements
  70.                     oRange = oSheetRanges.NextElement
  71.                     If oRange.getPropertyState("NumberFormat") = 1 Then
  72.                         If oRange.CellStyle = CurStyleName Then
  73.                             oSelRanges.InsertbyName("",oRange)
  74.                         End If
  75.                     End If
  76.                 Wend
  77.             Next i
  78.         Else
  79.             ' Hard Formatation is selected
  80.             a = -1
  81.             For n = 0 To Ubound(Listbox.SelectedItems())
  82.                 m = Listbox.SelectedItems(n)
  83.                 RangeName = Listbox.StringItemList(m)
  84.                 oListSheet = RetrieveSheetoutofRangeName(RangeName)
  85.                 a = a + 1
  86.                 MaxIndex = Ubound(SelRangeList())
  87.                 If a > MaxIndex Then
  88.                     Redim Preserve SelRangeList(MaxIndex + SBRANGEUBOUND)
  89.                 End If
  90.                 SelRangeList(a) = RangeName
  91.                 If oListSheet.Name = sCurSheetName Then
  92.                     oRange = RetrieveRangeoutofRangeName(RangeName)
  93.                     oSelRanges.InsertbyName("",oRange)
  94.                 End If
  95.             Next n
  96.         End If
  97.         If a > -1 Then
  98.             ReDim Preserve SelRangeList(a)
  99.         Else
  100.             ReDim SelRangeList()
  101.         End If
  102.         oDocument.CurrentController.Select(oSelRanges)
  103.         EnableStep1DialogControls(True, True, True)
  104.     End If
  105. End Sub
  106.  
  107.  
  108. ' Prozedur that is called by an event
  109. Sub RetrieveEnableValue()
  110. Dim EnableValue as Boolean
  111.     EnableValue = Not DialogModel.lstSelection.Enabled
  112.     EnableStep1DialogControls(True, EnableValue, True)
  113. End Sub
  114.  
  115.  
  116. Sub EnableStep1DialogControls(bCurrEnabled as Boolean, bFrameEnabled as Boolean, bButtonsEnabled as Boolean)
  117. Dim bCurrIsSelected as Boolean
  118. Dim bObjectIsSelected as Boolean
  119. Dim bConvertWholeDoc as Boolean
  120. Dim bDoEnableFrame as Boolean
  121.     bConvertWholeDoc  = DialogModel.chkComplete.State = 1
  122.     bDoEnableFrame = bFrameEnabled And (NOT bConvertWholeDoc)
  123.  
  124.     ' Controls around the Selection Listbox
  125.     With DialogModel
  126.         .lblCurrencies.Enabled = bCurrEnabled
  127.         .lstCurrencies.Enabled = bCurrEnabled
  128.         .lstSelection.Enabled = bDoEnableFrame
  129.         .lblSelection.Enabled = bDoEnableFrame
  130.         .hlnSelection.Enabled = bDoEnableFrame
  131.         .optCellTemplates.Enabled = bDoEnableFrame
  132.         .optSheetRanges.Enabled = bDoEnableFrame
  133.         .optDocRanges.Enabled = bDoEnableFrame
  134.         .optSelRange.Enabled = bDoEnableFrame
  135.     End With
  136.     ' The CheckBox has the Value '1' when the Controls in the Frame are disabled
  137.     If bButtonsEnabled Then
  138.         bCurrIsSelected = Ubound(DialogModel.lstCurrencies.SelectedItems()) <> -1
  139.         ' Enable GoOnButton only when Currency is selected
  140.         DialogModel.cmdGoOn.Enabled =  bCurrIsSelected
  141.         DialogModel.chkComplete.Enabled = bCurrIsSelected
  142.         If bDoEnableFrame AND DialogModel.cmdGoOn.Enabled Then
  143.             ' If FrameControls are enabled, check if Listbox is Empty
  144.             bObjectIsSelected = Ubound(DialogModel.lstSelection.SelectedItems()) <> -1
  145.             DialogModel.cmdGoOn.Enabled = bObjectIsSelected
  146.         End If
  147.     Else
  148.         DialogModel.cmdGoOn.Enabled = False
  149.         DialogModel.chkComplete.Enabled = False
  150.     End If
  151. End Sub
  152.  
  153.  
  154. Sub ConvertRangesOrStylesOfDocument()
  155. Dim i as Integer
  156. Dim ItemName as String
  157. Dim SelList() as String
  158. Dim oSheetRanges as Object
  159.  
  160.     bDocHasProtectedSheets = CheckSheetProtection(oSheets)
  161.     If bDocHasProtectedSheets Then
  162.         bDocHasProtectedSheets = UnprotectSheetsWithPassWord(oSheets, bDoUnProtect)
  163.         DialogModel.cmdGoOn.Enabled = False
  164.     End If
  165.     If Not bDocHasProtectedSheets Then
  166.         EnableStep1DialogControls(False, False, False)
  167.         InitializeProgressBar()
  168.         If DialogModel.optSelRange.State = 1 Then
  169.             SelectListItem()
  170.         End If
  171.         SelList() =  DialogConvert.GetControl("lstSelection").SelectedItems()
  172.         If DialogModel.optCellTemplates.State = 1 Then
  173.             ' Option 'Soft' Formatation is selected
  174.             AssignRangestoStyle(DialogModel.lstSelection.StringItemList(), SelList())
  175.             ConverttheSoftWay(SelList(), True)
  176.         ElseIf DialogModel.optSelRange.State = 1 Then
  177.             oSheetRanges = oPreSelRange.CellFormatRanges.createEnumeration
  178.             While oSheetRanges.hasMoreElements
  179.                 oRange = oSheetRanges.NextElement
  180.                 If CheckFormatType(oRange) Then
  181.                     ConvertCellCurrencies(oRange)
  182.                     SwitchNumberFormat(oRange, oFormats, sEuroSign)
  183.                 End If
  184.             Wend
  185.         Else
  186.             ConverttheHardWay(SelList(), False, True)
  187.         End If
  188.         oStatusline.End
  189.         EnableStep1DialogControls(True, False, True)
  190.         DialogModel.cmdGoOn.Enabled = True
  191.         oDocument.CurrentController.Select(oSelRanges)
  192.     End If
  193. End Sub
  194.  
  195.  
  196. Sub ConvertWholeDocument()
  197. Dim s as Integer
  198.     DialogModel.cmdGoOn.Enabled = False
  199.     DialogModel.chkComplete.Enabled = False
  200.     GoOn = ConvertDocument()
  201.     EmptyListbox(DialogModel.lstSelection())
  202.     EnableStep1DialogControls(True, True, True)
  203. End Sub
  204.  
  205.  
  206. ' Alles was selektiert wurde wird deselektiert
  207. Sub EmptySelection()
  208. Dim RangeName as String
  209. Dim i as Integer
  210. Dim MaxIndex as Integer
  211. Dim EmptySelRangeList() as String
  212.  
  213.     If Not IsNull(oSelRanges) Then
  214.         If oSelRanges.HasElements Then
  215.             EmptySelRangeList() = ArrayOutofString(oSelRanges.RangeAddressesasString, ";", MaxIndex)
  216.             For i = 0 To MaxIndex
  217.                 oSelRanges.RemovebyName(EmptySelRangeList(i))
  218.             Next i
  219.         End If
  220.         oDocument.CurrentController.Select(oSelRanges)
  221.     Else
  222.         oSelRanges = oDocument.createInstance("com.sun.star.sheet.SheetCellRanges")
  223.     End If
  224. End Sub
  225.  
  226.  
  227. Function AddSelectedRangeToSelRangesEnum() as Object
  228. Dim oLocRange as Object
  229.     osheet = oDocument.CurrentController.GetActiveSheet
  230.     oSelRanges = oDocument.createInstance("com.sun.star.sheet.SheetCellRanges")
  231.     ' Check if a Currency-Range has been selected
  232.     oLocRange = oDocument.CurrentController.Selection
  233.     bPreSelected = oLocRange.SupportsService("com.sun.star.sheet.SheetCellRange")
  234.     If bPreSelected Then
  235.         oSelRanges.InsertbyName("",oLocRange)
  236.         AddSelectedRangeToSelRangesEnum() = oLocRange
  237.     End If
  238. End Function
  239.  
  240.  
  241. Sub GetPreSelectedRange()
  242. Dim i as Integer
  243. Dim OldCurrSymbolList(2) as String
  244. Dim OldCurrIndex as Integer
  245. Dim OldCurExtension(2) as String
  246.     oPreSelRange = AddSelectedRangeToSelRangesEnum()
  247.     
  248.     DialogModel.chkComplete.State = Abs(Not(bPreSelected))
  249.     If bPreSelected Then
  250.         DialogModel.optSelRange.State = 1
  251.         AddRangeToListbox(oPreSelRange)
  252.     Else
  253.         DialogModel.optCellTemplates.State  = 1
  254.         CreateStyleEnumeration()
  255.     End If
  256.     EnableStep1DialogControls(True, bPreSelected, True)
  257.     DialogModel.optSelRange.Enabled = bPreSelected
  258. End Sub
  259.  
  260.  
  261. Sub AddRangeToListbox(oLocRange as Object)
  262.     EmptyListBox(DialogModel.lstSelection)
  263.     ' Den Namen der Range ermitteln und in ein Array packen
  264.     PreName = RetrieveRangeNamefromAddress(oLocRange)
  265.     AddSingleItemToListbox(DialogModel.lstSelection, Prename)', 0)
  266.     SelectListboxItem(DialogModel.lstCurrencies, CurrIndex)
  267.     TotCellCount = CountRangeCells(oLocRange)
  268. End Sub
  269.  
  270.  
  271. Sub CheckRangeSelection(Optional oEvent)
  272. ' Todo: Beim Startup werden die folgenden zwei Zeilen doppelt ausgef├╝hrt
  273.     EmptySelection()
  274.     AddRangeToListbox(oPreSelRange)
  275.     oPreSelRange = AddSelectedRangeToSelRangesEnum()    
  276. End Sub
  277.  
  278.  
  279. ' Checks if a Field (LocField) is already defined in an Array
  280. ' Returns 'True' or 'False'
  281. Function FieldinList(LocList(), MaxIndex as integer, ByVal LocField ) As Boolean
  282. Dim i as integer
  283.     LocField = Ucase(LocField)
  284.     For i = Lbound(LocList()) to MaxIndex
  285.         If Ucase(LocList(i)) = LocField  then
  286.             FieldInList = True
  287.             Exit Function
  288.         End if
  289.     Next
  290.     FieldInList = False
  291. End Function
  292.  
  293.  
  294. Function CheckLocale(oLocale) as Boolean
  295. Dim i as Integer
  296. Dim LocCountry as String
  297. Dim LocLanguage as String
  298.     LocCountry = oLocale.Country
  299.     LocLanguage = oLocale.Language
  300.     For i = 0 To 1
  301.         If LocLanguage = LangIDValue(CurrIndex,i,0) AND LocCountry = LangIDValue(CurrIndex,i,1) Then
  302.             CheckLocale = True
  303.             Exit Function
  304.         End If
  305.     Next i
  306.     CheckLocale = False
  307. End Function
  308.  
  309.  
  310. Sub    SetOptionValuestoNull()
  311.     With DialogModel
  312.         .optCellTemplates.State = 0
  313.         .optSheetRanges.State = 0
  314.         .optDocRanges.State = 0
  315.         .optSelRange.State = 0
  316.     End With
  317. End Sub
  318. </script:module>